
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;
import metier.Simulateur;
import java.awt.Toolkit;
import sun.audio.*;
import java.io.*;
/**
 *
 * @author Vincent
 */
public class DialogueTailleGrille extends javax.swing.JFrame {
    MenuPrincipal menu;
    /**
     * Creates new form DialogueTrailleGrille
     */
    public DialogueTailleGrille(MenuPrincipal menu) {
        initComponents();
        //Permet d'éviter les redimensionnements de la fenêtre
        this.menu = menu;
        setResizable(false);
        setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-getWidth()/2,
                Toolkit.getDefaultToolkit().getScreenSize().height/2-getHeight()/2);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titreLabel = new javax.swing.JLabel();
        tailleSlider = new javax.swing.JSlider();
        tailleLabel = new javax.swing.JLabel();
        validerBouton = new javax.swing.JButton();
        boutonAnnuler = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setResizable(false);

        titreLabel.setText("Veuillez indiquer la taille de la grille désirée (max 120 cases)");

        tailleSlider.setMaximum(120);
        tailleSlider.setMinimum(10);
        tailleSlider.setValue(100);
        tailleSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tailleSliderStateChanged(evt);
            }
        });

        tailleLabel.setText("Taille de la grille : 100 cases");
        tailleLabel.setToolTipText("");

        validerBouton.setText("OK");
        validerBouton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                validerBoutonMouseClicked(evt);
            }
        });

        boutonAnnuler.setText("Annuler");
        boutonAnnuler.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                boutonAnnulerMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(titreLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(tailleSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(tailleLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(validerBouton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boutonAnnuler)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titreLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tailleSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tailleLabel)
                    .addComponent(validerBouton)
                    .addComponent(boutonAnnuler))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tailleSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tailleSliderStateChanged
        // TODO add your handling code here:
        tailleLabel.setText("Taille de la grille : "+tailleSlider.getValue()+" cases");
    }//GEN-LAST:event_tailleSliderStateChanged

    private void validerBoutonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_validerBoutonMouseClicked
        // TODO add your handling code here:
        
        try {
            InputStream in = new FileInputStream("sounds/blouik.wav");
            AudioStream as = new AudioStream(in);
            AudioPlayer.player.start(as);
        } catch (Exception e){}
        
        new SimIHM(menu, tailleSlider.getValue()+2, null).setVisible(true);
        dispose();
    }//GEN-LAST:event_validerBoutonMouseClicked

    private void boutonAnnulerMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boutonAnnulerMouseReleased
        // TODO add your handling code here:
        menu.setVisible(true);
        dispose();
    }//GEN-LAST:event_boutonAnnulerMouseReleased

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(DialogueTailleGrille.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(DialogueTailleGrille.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(DialogueTailleGrille.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(DialogueTailleGrille.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//        
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new DialogueTailleGrille().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton boutonAnnuler;
    private javax.swing.JLabel tailleLabel;
    private javax.swing.JSlider tailleSlider;
    private javax.swing.JLabel titreLabel;
    private javax.swing.JButton validerBouton;
    // End of variables declaration//GEN-END:variables
}
